package com.shu.timerTask;

import org.junit.Test;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2019/4/8 13:56
 */

public class SchedueldService extends Base {

    @Test
    public void name() throws InterruptedException {
        Runnable runnable = () -> {
            System.out.println("--执行定时任务--" + stopWatch.elapsed(TimeUnit.MILLISECONDS));
            downLatch10.countDown();
        };

        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1);
        stopWatch.start();
//        scheduledThreadPool.scheduleAtFixedRate(runnable, 1,10, TimeUnit.MILLISECONDS);
        scheduledThreadPool.scheduleWithFixedDelay(runnable, 1,10, TimeUnit.MILLISECONDS);
        System.out.println("--开始定时任务--" + stopWatch.elapsed(TimeUnit.MILLISECONDS));
        downLatch10.await();
    }
}
